package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.AggSumDTO;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.FormDataSummaryDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.AggSumVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FocusDTO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerRestoreBatchDTO;
import com.xbongbong.pro.defaultData.pojo.dto.DefaultDataDTO;
import com.xbongbong.pro.defaultData.pojo.vo.DefaultDataVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.opportunity.pojo.dto.OpportunityDeleteBatchDTO;
import com.xbongbong.pro.opportunity.pojo.dto.OpportunityEditAttrUpdateDTO;
import com.xbongbong.pro.opportunity.pojo.dto.OpportunityUpdateBatchDTO;
import com.xbongbong.pro.opportunity.pojo.dto.OpportunityUpdateByBusinessRuleDTO;
import com.xbongbong.pro.opportunity.pojo.vo.OpportunityDeleteBatchVO;
import com.xbongbong.pro.opportunity.pojo.vo.OpportunityUpdateBatchVO;
import com.xbongbong.pro.opportunity.pojo.vo.OpportunityUpdateByBusinessRuleVO;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.saas.domain.entity.OpportunityProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/21 20:44
 * @since v1.0
 */
public interface OpportunityService {
    /**
     * 销售机会保存前校验
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-01-21 20:46
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;
    /**
     * 销售机会保存后逻辑
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-01-21 20:47
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;


    /**
     * 机会关注
     * @param focusDTO 重点关注
     * @return BaseVO
     * @throws XbbException XbbException
     */
    BaseVO focus(FocusDTO focusDTO) throws XbbException;

    /**
     * 根据业务规则修改数据
     * @author 吴峰
     * @date 2019/2/17 15:27
     * @param opportunityUpdateByBusinessRuleDTO 规则更新数据
     * @return com.xbongbong.pro.opportunity.pojo.vo.UpdateOpportunityByBusinessRuleVO
     * @throws XbbException XbbException
     */
    OpportunityUpdateByBusinessRuleVO updateFormDataByBusinessRule(OpportunityUpdateByBusinessRuleDTO opportunityUpdateByBusinessRuleDTO) throws XbbException;

    /**
     * 格式化产品，显示给前端
     * @param dataList bom单实体数据
     * @param saasAnalysisDataDTO 数据解析DTO
     * @author long.rao
     * @date 2019-02-01 15:19
     */
    void formatProduct4Show(JSONObject dataList, SaasAnalysisDataDTO saasAnalysisDataDTO) throws XbbException;

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/10 16:46
     * @param opportunityDeleteBatchDTO
     * @return com.xbongbong.pro.opportunity.pojo.vo.OpportunityDeleteBatchVO
     * @throws XbbException 业务异常
     */
    OpportunityDeleteBatchVO deleteBatch(OpportunityDeleteBatchDTO opportunityDeleteBatchDTO) throws XbbException;

    /**
     * 格式化移动端列表页
     *
     * @param formDataListDTO 用户
     * @param esEntities 业务实体集合
     * @param totalCount 总数
     * @return ListAppVO
     * @throws XbbException
     * @author long.rao
     * @date 2019-03-12 18:55
     */
    ListAppVO formatOpportunityAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException;

    /**
     * 关联新建时格式化解释
     *
     * @param handlerExplainInLinkItemDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;
    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/19 14:58
     * @param opportunityUpdateBatchDTO
     * @return OpportunityUpdateBatchVO
     * @throws XbbException 业务异常
     */
    OpportunityUpdateBatchVO updateBatch(OpportunityUpdateBatchDTO opportunityUpdateBatchDTO) throws XbbException;

    void updateBatch4Script(OpportunityUpdateBatchDTO opportunityUpdateBatchDTO, boolean async) throws XbbException;

    void updateBatch4Sync(OpportunityUpdateBatchDTO opportunityUpdateBatchDTO) throws XbbException;

    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/19 14:58
     * @param opportunityEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(OpportunityEditAttrUpdateDTO opportunityEditAttrUpdateDTO) throws XbbException;

    /**
     * 获取机会关联产品
     *
     * @param businessProductListDTO
     * @param object
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-04-09 16:42
     * @since v1.0
     * @version v1.0
     */
//    BusinessProductListVO getOpportunityProductList(BusinessProductListDTO businessProductListDTO, Object object) throws XbbException;

    /**
     * 通过客户id获取机会
     *
     * @param  corpid       公司id
     * @param  customerId   客户id
     * @author long.rao
     * @date 2019-04-17 20:30
     */
    List<PaasFormDataEntityExt> getOpportunityEsDataListByCustomerId(String corpid, Long customerId) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;
    /**
     * Description: 数据一致性更新机会的关联客户
     * @param corpid
     * @param customerId
     * @param customerName
     * @author 魏荣杰
     * @date 2019/6/12 9:31
     * @since v1.0
     */
    void dataConsistencyUpdateCustomer(String corpid, Long customerId, String customerName) throws XbbException;
    /**
     * Description: 数据一致性更新机会的关联竞争对手和赢单竞品
     * @param corpid
     * @param competitorId
     * @param competitorName
     * @author 应剑锋
     * @date 2022/9/9
     * @since v1.0
     */
    void dataConsistencyUpdateCompetitor(String corpid, Long competitorId, String competitorName) throws XbbException;
    /**
     * Description: 数据一致性更新机会的关联联系人
     * @param corpid
     * @param contactId
     * @param contactName
     * @author 魏荣杰
     * @date 2019/6/12 9:31
     * @since v1.0
     */
    void dataConsistencyUpdateContact(String corpid, Long contactId, String contactName) throws XbbException;

    /**
     * 计算机会毛利率汇总
     * @param numCountList
     * @param formDataSummaryDTO
     * @param aggAvgFieldList
     * @return
     * @throws XbbException
     */
    List<AggSumVO> aggAvgByField(List<AggSumVO> numCountList, FormDataSummaryDTO formDataSummaryDTO, List<AggSumDTO> aggAvgFieldList) throws XbbException;

    /**
     * 更新回滚
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 汇总机会产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * 还原数据
     * @author xingxing.xiao
     */
    void restoreBatch(String corpid, Map<Long, Long> customerUpdateTimeMap, CustomerRestoreBatchDTO customerRestoreBatchDTO) throws XbbException;

    /**
     * 将机会的某些值作为别的业务保存时的默认值
     *
     * @param businessDataDTO
     * @param explainMap
     * @param quotationEntity
     * @throws
     * @author long.rao
     * @date 2019-10-09 10:46
     */
    DefaultDataVO getOppDefault(DefaultDataDTO businessDataDTO, Map<String, FieldAttrEntity> explainMap, PaasFormDataEntityExt quotationEntity) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    /**
     * 解析单个产品
     * @param entity
     * @return
     */
    JSONObject formatSingleProduct(OpportunityProductEntity entity);

    /**
     * Description: 获取机会名称集合
     * @param handoverIdSet
     * @param corpid
     * @author 刘阳
     * @date 2020/1/8 2:41 PM
     * @since v1.0
     */
    Map<Long, String> getOpportunityNameMap(List<Long> handoverIdSet, String corpid) throws XbbException;

    void autoAdd(String corpid, String userName, String noticeName) throws XbbException;

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
